package com.musichord.core.unit.chord;

import java.util.List;
import java.util.Vector;

import com.musichord.core.helper.ChordHelper;
import com.musichord.core.helper.StringParser;

public class ToneInfo {
	public static int MAJOR = 0;
	public static int MINOR = 1;

	private int tone;
	private int root;
	private List<Integer> naturalPitches;
	private List<Chord> Tset;
	private List<Chord> Sset;
	private List<Chord> Dset;

	public ToneInfo(int root, int tone) {
		this.root = root;

		this.tone = tone;
		this.CreateNaturalPitches();

		this.CreateChordSet();

	}

	private void CreateChordSet() {
		int duration = ChordHelper.CHORD_UNIT_DURATION;
		TexturePattern texturePattern = new TexturePattern();

		/* T set */
		this.Tset = new Vector<Chord>();
		/* I */
		Tset.add(new Chord(root, duration, StringParser.PitchPatternMap
				.get("maj"), texturePattern));
		/* VIm */
		Tset.add(new Chord(root + 9, duration, StringParser.PitchPatternMap
				.get("m"), texturePattern));
		/* IV */
		Tset.add(new Chord(root + 5, duration, StringParser.PitchPatternMap
				.get("maj"), texturePattern));
		/* IIIm */
		Tset.add(new Chord(root + 4, duration, StringParser.PitchPatternMap
				.get("m"), texturePattern));

		/* S set */
		this.Sset = new Vector<Chord>();
		/* IV */
		Sset.add(new Chord(root + 5, duration, StringParser.PitchPatternMap
				.get("maj"), texturePattern));
		/* IIm */
		Sset.add(new Chord(root + 2, duration, StringParser.PitchPatternMap
				.get("m"), texturePattern));
		/* VIm */
		Sset.add(new Chord(root + 9, duration, StringParser.PitchPatternMap
				.get("m"), texturePattern));
		/* VIIdim */
		Sset.add(new Chord(root + 11, duration, StringParser.PitchPatternMap
				.get("dim"), texturePattern));

		/* D set */
		this.Dset = new Vector<Chord>();
		/* V */
		Dset.add(new Chord(root + 7, duration, StringParser.PitchPatternMap
				.get("maj"), texturePattern));
		/* Em */
		Dset.add(new Chord(root + 4, duration, StringParser.PitchPatternMap
				.get("m"), texturePattern));
		/* IIm */
		Dset.add(new Chord(root + 2, duration, StringParser.PitchPatternMap
				.get("m"), texturePattern));
		/* VIIdim */
		Dset.add(new Chord(root + 11, duration, StringParser.PitchPatternMap
				.get("dim"), texturePattern));
		/* E */
		Dset.add(new Chord(root + 4, duration, StringParser.PitchPatternMap
				.get("maj"), texturePattern));
	}

	private void CreateNaturalPitches() {
		this.naturalPitches = new Vector<Integer>();
		if (tone == MINOR) {
			this.naturalPitches.add(root + 0);
			this.naturalPitches.add(root + 2);
			this.naturalPitches.add(root + 3);
			this.naturalPitches.add(root + 5);
			this.naturalPitches.add(root + 7);
			this.naturalPitches.add(root + 8);
			this.naturalPitches.add(root + 10);
		} else if (tone == MAJOR) {
			this.naturalPitches.add(root + 0);
			this.naturalPitches.add(root + 2);
			this.naturalPitches.add(root + 4);
			this.naturalPitches.add(root + 5);
			this.naturalPitches.add(root + 7);
			this.naturalPitches.add(root + 9);
			this.naturalPitches.add(root + 11);
		}
	}

	public int getTone() {
		return tone;
	}

	public int getRoot() {
		return root;
	}

	public List<Integer> getNaturalPitches() {
		return naturalPitches;
	}

	public List<Chord> getTset() {
		return Tset;
	}

	public List<Chord> getSset() {
		return Sset;
	}

	public List<Chord> getDset() {
		return Dset;
	}

}
